package com.casework

import org.joda.time.LocalDate

class SearchQueryController {

    def excelService
    static scaffold = true
    def index = { }

    def generateExcel = {QueryCommand queryCommand ->
        response.setHeader "Content-disposition", "attachment;filename=search-results-from-${queryCommand.fromDate}-to-${queryCommand.toDate}.xls"
        response.contentType = 'application/vnd.ms-excel'
        def file = excelService.generateExcelSpreadSheet( queryCommand.fromDate, queryCommand.toDate)
        response.outputStream << file.bytes
        response.outputStream.flush()
        response.outputStream.close()
        file.delete()
    }
}
class QueryCommand {
    LocalDate fromDate = new LocalDate().minusMonths(1)
    LocalDate toDate = new LocalDate()
}